<template>
  <div>
    <div class="top-show" v-show="isTopShow">
      <top-bar class="top-bar-clone">
        <template #left>
          <div @click="toCity">
            <current-city />
            <i class="iconfont icon-xia"></i>
          </div>
        </template>
        <template #center>
          <span>电影</span>
        </template>
        <template #right>
          <div @click="toSearch">
            <i class="iconfont icon-fangdajing"></i>
          </div>
        </template>
      </top-bar>
      <tab-control class="tab-control-clone" />
    </div>
    <b-scroll
      class="wrapper"
      ref="wrapper"
      :probeType="3"
      :listenScroll="true"
      @listenScroll="listenScroll"
      :scrollEnd="true"
      @scrollEnd="scrollEnd"
    >
      <div>
        <top-bar ref="top-bar" class="top_he">
          <template #left>
            <div @click="toCity">
              <current-city />
              <i class="iconfont icon-xia"></i>
            </div>
          </template>
          <template #center>
            <span>电影</span>
          </template>
          <template #right>
            <i class="iconfont icon-fangdajing"></i>
          </template>
        </top-bar>
        <!-- 轮播图 -->
        <movies-swiper ref="swiper"></movies-swiper>
        <!-- 选项卡 -->
        <tab-control ref="tabControl"></tab-control>
        <!-- 选项卡二级路由 -->
        <keep-alive include="NowPlaying">
          <router-view ref="moiveList"
        /></keep-alive>
      </div>
    </b-scroll>
  </div>
</template>

<script>
import MoviesSwiper from "./movies/MoviesSwiper";
import TabControl from "./movies/TabControl";
import NowPlaying from "./movies/NowPlaying";
import ComingSoon from "./movies/ComingSoon";
import BScroll from "@/components/BScroll";
import TopBar from "@/components/TopBar";
import CurrentCity from "@/components/CurrentCity";

export default {
  data() {
    return {
      isTopShow: false, // 复制品默认不显示
    };
  },
  components: {
    MoviesSwiper,
    TabControl,
    NowPlaying,
    ComingSoon,
    BScroll,
    TopBar,
    CurrentCity,
  },
  methods: {
    listenScroll(e) {
      const tabContrTop = this.$refs.tabControl.$el.offsetTop;
      this.isTopShow = -e.y >= tabContrTop;
    },
    scrollEnd() {
      // 上拉以后调用子组件pullUpGetMore()方法
      this.$refs.moiveList.scrollEndGetMore();
    },
    toCity() {
      this.$router.push("/city");
    },
    toSearch() {
      this.$router.push("/search");
    },
  },
};
</script>

<style scoped  lang="less" >
.wrapper {
  height: calc(100vh - 49px);
}
.top-show {
  position: fixed;
  top: 0;
  right: 0;
  left: 0;
  z-index: 9;
  background-color: #fff;
  border-radius: 0 0 10px 10px;
  box-shadow: 0 4px 4px #ccc;
  overflow: hidden;
}
// 头部导航栏
.top_he {
  display: none;
}
</style>